package javabase.schoolwork.day6_19;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author fance
 * @date 2018/6/19 23:06
 */
public class TCPServer {
    public static void main(String[] args) throws IOException {
        ServerSocket server=null;
        Socket client=null;
        PrintStream out=null;
        server=new ServerSocket(8888);
//        System.out.println("��������");
        client=server.accept();

        /*out = new PrintStream(client.getOutputStream());
        sendPicture(out);
        out.close();
*/

        InputStream inputStream = client.getInputStream();
        saveTxt(inputStream);
        client.close();
        server.close();
    }

    public static void sendPicture(OutputStream out) throws IOException {
        FileInputStream fileInputStream =
                new FileInputStream("D:\\codefuninwindows\\src\\javabase\\schoolwork\\day6_19\\test\\picture1.jpg");

        byte[] buffer = new byte[1024];
        while (fileInputStream.read(buffer) != -1) {
            out.write(buffer);
        }
    }


    public static void saveTxt(InputStream in) throws IOException {
        FileOutputStream fos=new FileOutputStream("D:\\codefuninwindows\\src\\javabase\\schoolwork\\day6_19\\test\\test.txt");
        byte[] b=new byte[1024];

        while(in.read(b)!=-1) {

            fos.write(b);
        }
    }
}
